﻿<%@ Page Language="VB" AutoEventWireup="false" CodeFile="P04_Edit.aspx.vb" Inherits="P04_Edit" %>

<%@ Register Assembly="ISNet.WebUI.WebInput" Namespace="ISNet.WebUI.WebControls" TagPrefix="ISWebInput" %>
<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
    <style>
        input {
            font-family: Tahoma !important;
            font-size: 10px !important;
        }

        html * {
            font-family: Tahoma;
            font-size: 10px;
        }
    </style>
    <style>
        .WI3-F-N {
            border: none !important;
        }

        .WI3-F-O {
            border: none !important;
        }

        .tdstyle {
            border: 1px solid #808080;
            font-family: Tahoma;
            vertical-align: top;
            background-color: lightgray;
        }

        .tdstyle2 {
            border: 1px solid #808080;
            font-family: Tahoma;
            vertical-align: top;
        }

        .tdstyle3 {
            text-align: center;
            border: 1px solid #808080;
            font-family: Tahoma;
            vertical-align: top;
            font-size: 11px;
            background-color: #75b6ed;
        }
    </style>
    <script>
        function ClosePop() {
            window.parent.TINY.box.hide();
        }

        function isNumberKey(evt) {
            var charCode = (evt.which) ? evt.which : event.keyCode

            if (charCode > 31 && (charCode < 48 || charCode > 57) && charCode != 46)
                return false;

            return true;
        }
        function ClearComma(obj) {
            var str = "";

            str = obj.value;
            str = str.replace(/\,/g, '');

            obj.value = str;
            var n = str.length;

            SelectPos(obj, n);
        }

        function SelectPos(obj, pos) {
            var input = obj;
            if ('selectionStart' in input) {
                input.selectionStart = pos;
                input.selectionEnd = pos;
                input.focus();
            }
            else {  // Internet Explorer before version 9
                var inputRange = input.createTextRange();
                inputRange.moveStart("character", pos);
                inputRange.collapse();
                inputRange.moveEnd("character", pos);
                inputRange.select();
            }
        }

        function SetComma(obj) {
            var x;
            x = obj.value;
            var y;
            y = parseFloat(x);
            x = y.toFixed(2);
            x = addCommas(x)
            //x = x.replace(/\.00$/, '');
            obj.value = x;

            CalSum();
        }

        function addCommas(NumberStr) {
            NumberStr = parseFloat(NumberStr).toFixed(2);
            NumberStr += '';
            NumberData = NumberStr.split('.');
            Number1 = NumberData[0];
            Number2 = NumberData.length > 1 ? '.' + NumberData[1] : '';
            var rgx = /(\d+)(\d{3})/;
            while (rgx.test(Number1)) {
                Number1 = Number1.replace(rgx, '$1' + ',' + '$2');
            }
            var FinalNum = Number1 + Number2;
            FinalNum = FinalNum.replace(/\.00$/, '');
            return FinalNum;
        }

        function CalSum() {
            var AS0 = 0;
            // calculate ผลจริง of month 1-5 of previous year
            for (var i = 1; i <= 5 ; i++) {
                AS0 += parseFloat(document.getElementById("A" + i.toString()).value.replace(/\,/g, ''))
            }
            document.getElementById("ASUM0").value = addCommas(AS0);

            var AS1 = 0;
            // calculate ผลจริง of month 6-12 of previous year
            for (var i = 6; i <= 12 ; i++) {
                AS1 += parseFloat(document.getElementById("A" + i.toString()).value.replace(/\,/g, ''))
            }
            document.getElementById("ASUM1").value = addCommas(AS0 + AS1);

            var AS2 = 0;
            // calculate ผลจริง of month 1-12 of current year
            for (var i = 13; i <= 24 ; i++) {
                AS2 += parseFloat(document.getElementById("A" + i.toString()).value.replace(/\,/g, ''))
            }
            document.getElementById("ASUM2").value = addCommas(AS2);
        }

        function DisableBtn() {
            try {
                var btn = document.getElementById("SaveDocument");
                btn.disabled = true;
            }
            catch (err) {
            }
        }
        window.onbeforeunload = DisableBtn;

        function WebInputOnKeyDown(controlId) {
            var textval = document.getElementById(controlId).value.toString();
            if (textval.length > 9) {
                if (event.keyCode < 48) {
                    return true;
                } else {
                    event.returnValue = false;
                    return false;
                }
            }
        }
    </script>
    <style>
        input[type="text"] {
            border: none;
            width: 67px;
            height: 18px;
            font-family: Tahoma;
            font-size: 10px !important;
        }

            input[type="text"].readonly {
                background-color: #f3f3f3;
            }

            input[type="text"].readonly2 {
                background-color: #ffeaea;
            }
    </style>
</head>
<body onkeydown="return (event.keyCode!=13)">
    <form id="form1" runat="server">
        <div>
            <asp:Label ID="name1" runat="server" Text="ชื่อผลิตภัณฑ์" Font-Size="12px" Font-Bold="true"></asp:Label>
            <table width="1000px" style="text-align: left; vertical-align: text-top; border: 1px solid #f3f3f3;" cellpadding="0" cellspacing="0">
                <tr>
                    <td class="tdstyle3" colspan="2"></td>
                    <td class="tdstyle3">ม.ค.</td>
                    <td class="tdstyle3">ก.พ.</td>
                    <td class="tdstyle3">มี.ค.</td>
                    <td class="tdstyle3">เม.ย.</td>
                    <td class="tdstyle3">พ.ค.</td>
                    <td class="tdstyle3">มิ.ย.</td>
                    <td class="tdstyle3">ก.ค.</td>
                    <td class="tdstyle3">ส.ค.</td>
                    <td class="tdstyle3">ก.ย.</td>
                    <td class="tdstyle3">ต.ค.</td>
                    <td class="tdstyle3">พ.ย.</td>
                    <td class="tdstyle3">ธ.ค.</td>
                    <td class="tdstyle3">รวม</td>
                </tr>
                <tr>
                    <td class="tdstyle2" width="43px" rowspan="2" style="text-align: center; font-size: 11px;">
                        <asp:Label ID="year1" runat="server" Text="y-1" Font-Size="11px"></asp:Label></td>
                    <td class="tdstyle2" width="80px" style="text-align: center; font-size: 11px;">ผลจริง</td>
                    <td class="tdstyle">
                        <asp:Label ID="A_ID" runat="server" Text="" Visible="false"></asp:Label>
                        <asp:Label ID="A_LAST2" runat="server" Text="" Visible="false"></asp:Label>
                        <input runat="server" tabindex="1" class="readonly" name="A1" id="A1" onkeypress="return isNumberKey(event)" onfocus="ClearComma(this)" onblur="SetComma(this);" type="text" readonly="true" />
                    </td>
                    <td class="tdstyle">
                        <input runat="server" tabindex="2" class="readonly" name="A2" id="A2" onkeypress="return isNumberKey(event)" onfocus="ClearComma(this)" onblur="SetComma(this);" type="text" readonly="true" />
                    </td>
                    <td class="tdstyle">
                        <input runat="server" tabindex="3" class="readonly" name="A3" id="A3" onkeypress="return isNumberKey(event)" onfocus="ClearComma(this)" onblur="SetComma(this);" type="text" readonly="true" />
                    </td>
                    <td class="tdstyle">
                        <input runat="server" tabindex="4" class="readonly" name="A4" id="A4" onkeypress="return isNumberKey(event)" onfocus="ClearComma(this)" onblur="SetComma(this);" type="text" readonly="true" />
                    </td>
                    <td class="tdstyle">
                        <input runat="server" tabindex="5" class="readonly" name="A5" id="A5" onkeypress="return isNumberKey(event)" onfocus="ClearComma(this)" onblur="SetComma(this);" type="text" readonly="true" />
                    </td>
                    <td class="tdstyle"></td>
                    <td class="tdstyle"></td>
                    <td class="tdstyle"></td>
                    <td class="tdstyle"></td>
                    <td class="tdstyle"></td>
                    <td class="tdstyle"></td>
                    <td class="tdstyle"></td>
                    <td class="tdstyle">
                        <input runat="server" tabindex="6" class="readonly2" name="ASUM0" id="ASUM0" onkeypress="return isNumberKey(event)" onfocus="ClearComma(this)" onblur="SetComma(this);" type="text" readonly="true" style="visibility:hidden" />
                    </td>
                </tr>
                <tr>
                    <td class="tdstyle2" width="80px" style="text-align: center; font-size: 11px;">ประมาณการ</td>
                    <td class="tdstyle"></td>
                    <td class="tdstyle"></td>
                    <td class="tdstyle"></td>
                    <td class="tdstyle"></td>
                    <td class="tdstyle"></td>
                    <td class="tdstyle">
                        <input runat="server" tabindex="7" name="A6" id="A6" onkeypress="return isNumberKey(event)" onfocus="ClearComma(this)" onblur="SetComma(this);" type="text" maxlength="10" />
                    </td>
                    <td class="tdstyle">
                        <input runat="server" tabindex="8" name="A7" id="A7" onkeypress="return isNumberKey(event)" onfocus="ClearComma(this)" onblur="SetComma(this);" type="text" maxlength="10" />
                    </td>
                    <td class="tdstyle">
                        <input runat="server" tabindex="9" name="A8" id="A8" onkeypress="return isNumberKey(event)" onfocus="ClearComma(this)" onblur="SetComma(this);" type="text" maxlength="10" />
                    </td>
                    <td class="tdstyle">
                        <input runat="server" tabindex="10" name="A9" id="A9" onkeypress="return isNumberKey(event)" onfocus="ClearComma(this)" onblur="SetComma(this);" type="text" maxlength="10" />
                    </td>
                    <td class="tdstyle">
                        <input runat="server" tabindex="11" name="A10" id="A10" onkeypress="return isNumberKey(event)" onfocus="ClearComma(this)" onblur="SetComma(this);" type="text" maxlength="10" />
                    </td>
                    <td class="tdstyle">
                        <input runat="server" tabindex="12" name="A11" id="A11" onkeypress="return isNumberKey(event)" onfocus="ClearComma(this)" onblur="SetComma(this);" type="text" maxlength="10" />
                    </td>
                    <td class="tdstyle">
                        <input runat="server" tabindex="13" name="A12" id="A12" onkeypress="return isNumberKey(event)" onfocus="ClearComma(this)" onblur="SetComma(this);" type="text" maxlength="10" />
                    </td>
                    <td class="tdstyle">
                        <input runat="server"  tabindex="14" class="readonly2" name="ASUM1" id="ASUM1" onkeypress="return isNumberKey(event)" onfocus="ClearComma(this)" onblur="SetComma(this);" type="text" readonly="true" />
                    </td>
                </tr>
                <tr>
                    <td class="tdstyle2" width="43px" style="text-align: center; font-size: 11px;">
                        <asp:Label ID="year2" runat="server" Text="y" Font-Size="11px"></asp:Label></td>
                    <td class="tdstyle2" width="80px" style="text-align: center; font-size: 11px;">ประมาณการ</td>
                    <td class="tdstyle">
                        <input runat="server" tabindex="15" name="A13" id="A13" onkeypress="return isNumberKey(event)" onfocus="ClearComma(this)" onblur="SetComma(this);" type="text" maxlength="10" />
                    </td>
                    <td class="tdstyle">
                        <input runat="server" tabindex="16" name="A14" id="A14" onkeypress="return isNumberKey(event)" onfocus="ClearComma(this)" onblur="SetComma(this);" type="text" maxlength="10" />
                    </td>
                    <td class="tdstyle">
                        <input runat="server" tabindex="17" name="A15" id="A15" onkeypress="return isNumberKey(event)" onfocus="ClearComma(this)" onblur="SetComma(this);" type="text" maxlength="10" />
                    </td>
                    <td class="tdstyle">
                        <input runat="server" tabindex="18" name="A16" id="A16" onkeypress="return isNumberKey(event)" onfocus="ClearComma(this)" onblur="SetComma(this);" type="text" maxlength="10" />
                    </td>
                    <td class="tdstyle">
                        <input runat="server" tabindex="19" name="A17" id="A17" onkeypress="return isNumberKey(event)" onfocus="ClearComma(this)" onblur="SetComma(this);" type="text" maxlength="10" />
                    </td>
                    <td class="tdstyle">
                        <input runat="server" tabindex="20" name="A18" id="A18" onkeypress="return isNumberKey(event)" onfocus="ClearComma(this)" onblur="SetComma(this);" type="text" maxlength="10" />
                    </td>
                    <td class="tdstyle">
                        <input runat="server" tabindex="21" name="A19" id="A19" onkeypress="return isNumberKey(event)" onfocus="ClearComma(this)" onblur="SetComma(this);" type="text" maxlength="10" />
                    </td>
                    <td class="tdstyle">
                        <input runat="server" tabindex="22" name="A20" id="A20" onkeypress="return isNumberKey(event)" onfocus="ClearComma(this)" onblur="SetComma(this);" type="text" maxlength="10" />
                    </td>
                    <td class="tdstyle">
                        <input runat="server" tabindex="23" name="A21" id="A21" onkeypress="return isNumberKey(event)" onfocus="ClearComma(this)" onblur="SetComma(this);" type="text" maxlength="10" />
                    </td>
                    <td class="tdstyle">
                        <input runat="server" tabindex="24" name="A22" id="A22" onkeypress="return isNumberKey(event)" onfocus="ClearComma(this)" onblur="SetComma(this);" type="text" maxlength="10" />
                    </td>
                    <td class="tdstyle">
                        <input runat="server" tabindex="25" name="A23" id="A23" onkeypress="return isNumberKey(event)" onfocus="ClearComma(this)" onblur="SetComma(this);" type="text" maxlength="10" />
                    </td>
                    <td class="tdstyle">
                        <input runat="server" tabindex="26" name="A24" id="A24" onkeypress="return isNumberKey(event)" onfocus="ClearComma(this)" onblur="SetComma(this);" type="text" maxlength="10" />
                    </td>
                    <td class="tdstyle">
                        <input runat="server" tabindex="27" class="readonly2" name="ASUM2" id="ASUM2" onkeypress="return isNumberKey(event)" onfocus="ClearComma(this)" onblur="SetComma(this);" type="text" readonly="true" />
                    </td>
                </tr>
                <tr>
                    <td colspan="16">
                        <p style="color: red; font-family: Tahoma; font-size: 11px; margin: 0px">*หมายเหตุ : จำนวนเงินหลักพันบาท</p>
                    </td>
                </tr>
                <tr>
                    <td align="center" colspan="16">
                        <asp:Button ID="SaveDocument" runat="server" Text="บันทึก" Width="65px" />&nbsp;&nbsp;<asp:Button ID="CloseBtn" runat="server" Text="ปิด" Width="65px" OnClientClick="ClosePop()" /></td>
                </tr>
            </table>
        </div>

        <%=scripttext%>
    </form>
</body>
</html>
